<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Radiological Equipment Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

$today = date("Ymd");
$year = date("Y");
$month = date("m");
$day = date("d");
?>
<style type="text/css">
<!--
.unresolved {
  font-weight: bold;
  background-color: #EEEEEE;
}
.resolved {
  background-color: #FFFFFF;
}
-->
</style>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<h2>Open Survey Recommendations <?PHP echo $year; ?> YTD</h2>
<p>Shaded items indicate unresolved survey recommendations.</p>
<?PHP
// Get SurveyIDs for all unresolved surveys for current YTD.
$query = "SELECT DISTINCT Recommendations.SurveyID, TestDate
          FROM TestDates, Recommendations 
          WHERE TestDates.SurveyID=Recommendations.SurveyID
          AND Recommendations.Resolved = 0
          AND TestDate BETWEEN \"" . date("Y-m-d",mktime(0,0,0,1,1,$year)) . "\"
          AND \"" . date("Y-m-d",mktime(0,0,0,$month,$day,$year)) . "\"
          ORDER BY TestDate
          ";
$openRecSurveyID = mysql_query($query)
  or die("<p>Unable to execute query: $query<br />" . mysql_error() . "</p>\n");

// Loope through each of the survey IDs and get the details
while ($openRecSurveyID_row = mysql_fetch_row($openRecSurveyID)) {
  $SurveyID = $openRecSurveyID_row[0];
  $TestDate = $openRecSurveyID_row[1];
  // Get the machine information for this survey
  $query = "SELECT Description,VendSiteID,Manufacturer 
            FROM Survey2Machine
            LEFT JOIN Machines USING (MachineID)
            LEFT JOIN Manufacturer USING (ManufacturerID)
            WHERE SurveyID = $SurveyID";
  $machInfo = mysql_query($query)
    or die("<p>Unable to execute query: $query<br />" . mysql_error() . "</p>\n");
  $machInfo_row = mysql_fetch_row($machInfo);
  
  // Get the recommendations for this survey
  $query = "SELECT Recommendation, Resolved, RecAddTS, RecResolveTS, WONum
            FROM Recommendations
            WHERE SurveyID = $SurveyID";
  $recs = mysql_query($query)
    or die("<p>Unable to execute query: $query<br />" . mysql_error() . "</p>\n");

  echo "<h3>" . $machInfo_row[2] . " " . $machInfo_row[0] . " (Survey ID <a href=\"SurveyResRec.php?SurveyID=" . $SurveyID . "\">$SurveyID</a>)";
  if (!empty($machInfo_row[1])) echo " (Site ID " . $machInfo_row[1] . ")";
  echo "</h3>";
  echo "<table border=1>\n";
  echo "  <tr>\n";
  echo "    <th>Recommendation</th><th>Added</th><th>Resolved</th><th>Work Order</th>\n";
  echo "  </tr>\n";
  while ($recs_row = mysql_fetch_array($recs)) {
    echo "  <tr>\n";
    if ($recs_row['Resolved'] == 0) {
      echo "    <td class=\"unresolved\">";
    }
    else {
      echo "    <td class=\"resolved\">"; 
    }
    echo $recs_row['Recommendation'] . "</td>\n";
    echo "    <td>" . $recs_row['RecAddTS'] . "</td>\n";
    echo "    <td>" . $recs_row['RecResolveTS'] . "</td>\n";
    echo "    <td>" . $recs_row['WONum'] . "</td>\n";
    echo "  </tr>\n";
  }
  echo "</table>\n";
}
?>
<p><a href="index.html" target="_top" >Main</a></p>
</body>
</html>
